﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
$(function () {
    InitMainBody();
});
///初始化圆角
function InitMainBody() {
    $(".MainBody").each(function () {
        var contextBefore = "<b class=\"MainRoundTop\"><b class=\"MainRoundA\"></b><b class=\"MainRoundB\"></b><b class=\"MainRoundC\"></b><b class=\"MainRoundD\"></b></b>";
        var contextAfter = "<b class=\"MainRoundBottom\"><b class=\"MainRoundD\"></b><b class=\"MainRoundC\"></b><b class=\"MainRoundB\"></b><b class=\"MainRoundA\"></b></b>";
        //尽量不使用Jquery.wrap();因为与dev的js的callback函数冲突 by skzheng
        //$(this).wrap("<div class=\"MainRoundContentW\"></div>");
        //$(".MainRoundContentW").wrap("<div class=\"MainRoundContent\"></div>");
        //$(".MainRoundContent").wrap("<div class=\"MainRound\"></div>");
        $(".MainRoundContent").before(contextBefore);
        $(".MainRoundContent").after(contextAfter);
    });
}

//让iframe自动适应高度的方法
function SetWinHeight(obj) {
    var win = obj;
    if (document.getElementById) {
        if (win) {
            if (win.contentDocument && win.contentDocument.body.offsetHeight) {
                win.height = win.contentDocument.body.offsetHeight;
            }
            else if (win.Document && win.Document.body.scrollHeight) {
                win.height = win.Document.body.scrollHeight;
            }
        }
    }
}
//弹出窗口方法url=地址,title=标题,ID=该弹窗的唯一标示,dWidth=宽,dHeight=高
function Dialog(url, title, ID, dWidth, dHeight) {
    var isXhtml = (temp_h2 <= temp_h1 && temp_h2 != 0) ? true : false;
    var htmlbody = isXhtml ? document.documentElement : document.body;
    htmlbody.style.overflow = "hidden";
    var screenWidth = $(window).width();
    var screenHeight = $(window).height();
    var screenLeft = (screenWidth - dWidth) / 2;
    var screenTop = (screenHeight - dHeight) / 2;
    var context = "<div id=\"____lpllookmain" + ID + "\"  oncontextmenu=\"return false;\" style=\"position:absolute; left:0px; top:0px;width:" + screenWidth + "px; height:" + screenHeight + "px; background-color:#DAEBF6;filter: alpha(opacity=50);-moz-opacity: 0.5;opacity: 0.5;z-index:99999;\"></div>";
    context = context + "<div id=\"____lpllookbody" + ID + "\" style=\"position:absolute; width:" + (dWidth + 40) + "px; height:" + dHeight + "px; left:" + screenLeft + "px; top:" + screenTop + "px;height: auto; margin: 0 auto;z-index:99999999;\">";
    context = context + "<b class=\"MainRoundTop\"><b class=\"MainRoundA\"></b><b class=\"MainRoundB\" style=\"background-color: #93BEE2;\">";
    context = context + "</b><b class=\"MainRoundC\" style=\"background-color: #93BEE2;\"></b><b class=\"MainRoundD\" style=\"background-color: #93BEE2;\"></b></b>";
    context = context + "<div style=\"width: 100%; height: auto; margin: 0 auto; padding-bottom: 3px; background-color: #93BEE2;\">";
    context = context + "<div style=\"width: " + (dWidth + 30) + "px; height: auto; margin: 0 auto;\">";
    context = context + "<b class=\"MainRoundTop\"><b class=\"MainRoundA\"></b><b class=\"MainRoundB\" style=\"background-color: #ffffff;\">";
    context = context + "</b><b class=\"MainRoundC\" style=\"background-color: #ffffff;\"></b><b class=\"MainRoundD\" style=\"background-color: #ffffff;\"></b></b>";
    context = context + "<div class=\"MainRoundContent\" style=\"border-bottom: 1px solid #93BEE2; height: 100%; padding: 0 4px 4px 4px; background-color: #ffffff;\"><div>";
    context = context + "<b class=\"MainRoundTop\"><b class=\"MainRoundA\" style=\"background-color: #93BEE2;\"></b>";
    context = context + "<b class=\"MainRoundB\" style=\"background-color: #93BEE2;\"></b><b class=\"MainRoundC\" style=\"background-color: #93BEE2;\"></b><b class=\"MainRoundD\" style=\"background-color: #93BEE2;\"></b></b>";
    context = context + "<div class=\"MainRoundContent\" style=\"height: 25px; text-align: center; line-height: 20px;background-color: #93BEE2; font-family: 微软雅黑; color: White;\">";
    context = context + "<span style=\"float: right; font-size: 25px; margin-right: 3px; cursor: pointer;\" id=\"Close" + ID + "\">×</span>";
    context = context + "<span style=\"font-size: 18px; font-weight: bold;\">" + title + "</span>";
    context = context + "</div>";
    context = context + "<div class=\"scroll\" style=\"height: " + dHeight + "px; overflow: scroll; overflow-y: scroll; overflow-x: hidden;\">";
    context = context + "<div style=\"width: " + dWidth + "px;\">";
    context = context + "<iframe frameborder=\"0\"  class=\"iframe\" width=\"100%\" scrolling=\"no\" onload=\"javascript:SetWinHeight(this);\" src=\"" + url + "\"></iframe>";
    context = context + "</div>";
    context = context + "</div>";
    context = context + "</div>";
    context = context + "</div>";
    context = context + "</div>";
    context = context + "</div>";
    context = context + "</div>";
    $("body").append(context);
    var temp_h1 = document.body.clientHeight;
    var temp_h2 = document.documentElement.clientHeight;
    $(window).resize(function () {
        $("#____lpllookmain" + ID).css("width", $(window).width() + "px").css("height", $(window).height() + "px");
        $("#____lpllookbody" + ID).css("left", ($(window).width() - dWidth) / 2 + "px").css("top", ($(window).height() - dHeight) / 2 + "px");
    });
    $("#Close" + ID).click(function () {
        $("#____lpllookmain" + ID).remove();
        $("#____lpllookbody" + ID).remove();
        htmlbody.style.overflow = "scroll";
    });
}

//弹出窗口方法url=地址,title=标题,ID=该弹窗的唯一标示,dWidth=宽,dHeight=高
function DialogInfo(url, title, dWidth, dHeight, top) {
    var ID = "SelectItem";
    top = top + window.parent.$(".scroll").scrollTop();
    window.parent.$(".scroll").css("overflow", "hidden").css("overflow-y", "hidden");
    var isXhtml = (temp_h2 <= temp_h1 && temp_h2 != 0) ? true : false;
    var htmlbody = isXhtml ? document.documentElement : document.body;
    htmlbody.style.overflow = "hidden";
    var screenWidth = $(window).width();
    var screenHeight = $(window).height();
    var screenLeft = (screenWidth - dWidth) / 2;
    var screenTop = top;
    var context = "<div id=\"____lpllookmain" + ID + "\"  oncontextmenu=\"return false;\" style=\"position:absolute; left:0px; top:0px;width:" + screenWidth + "px; height:" + screenHeight + "px; background-color:#DAEBF6;filter: alpha(opacity=50);-moz-opacity: 0.5;opacity: 0.5;z-index:99999;\"></div>";
    context = context + "<div id=\"____lpllookbody" + ID + "\" style=\"position:absolute; width:" + (dWidth + 40) + "px; height:" + dHeight + "px; left:" + screenLeft + "px; top:" + screenTop + "px;height: auto; margin: 0 auto;z-index:99999999;\">";
    context = context + "<b class=\"MainRoundTop\"><b class=\"MainRoundA\"></b><b class=\"MainRoundB\" style=\"background-color: #93BEE2;\">";
    context = context + "</b><b class=\"MainRoundC\" style=\"background-color: #93BEE2;\"></b><b class=\"MainRoundD\" style=\"background-color: #93BEE2;\"></b></b>";
    context = context + "<div style=\"width: 100%; height: auto; margin: 0 auto; padding-bottom: 3px; background-color: #93BEE2;\">";
    context = context + "<div style=\"width: " + (dWidth + 30) + "px; height: auto; margin: 0 auto;\">";
    context = context + "<b class=\"MainRoundTop\"><b class=\"MainRoundA\"></b><b class=\"MainRoundB\" style=\"background-color: #ffffff;\">";
    context = context + "</b><b class=\"MainRoundC\" style=\"background-color: #ffffff;\"></b><b class=\"MainRoundD\" style=\"background-color: #ffffff;\"></b></b>";
    context = context + "<div class=\"MainRoundContent\" style=\"border-bottom: 1px solid #93BEE2; height: 100%; padding: 0 4px 4px 4px; background-color: #ffffff;\"><div>";
    context = context + "<b class=\"MainRoundTop\"><b class=\"MainRoundA\" style=\"background-color: #93BEE2;\"></b>";
    context = context + "<b class=\"MainRoundB\" style=\"background-color: #93BEE2;\"></b><b class=\"MainRoundC\" style=\"background-color: #93BEE2;\"></b><b class=\"MainRoundD\" style=\"background-color: #93BEE2;\"></b></b>";
    context = context + "<div class=\"MainRoundContent\" style=\"height: 25px; text-align: center; line-height: 20px;background-color: #93BEE2; font-family: 微软雅黑; color: White;\">";
    context = context + "<span style=\"float: right; font-size: 25px; margin-right: 3px; cursor: pointer;\" id=\"Close" + ID + "\">×</span>";
    context = context + "<span style=\"font-size: 18px; font-weight: bold;\">" + title + "</span>";
    context = context + "</div>";
    context = context + "<div class=\"scroll\" style=\"height: " + dHeight + "px; overflow: scroll; overflow-y: scroll; overflow-x: hidden;\">";
    context = context + "<div style=\"width: " + dWidth + "px;\">";
    context = context + "<iframe frameborder=\"0\" class=\"iframe\" width=\"100%\" scrolling=\"no\" onload=\"javascript:SetWinHeight(this);\" src=\"" + url + "\"></iframe>";
    context = context + "</div>";
    context = context + "</div>";
    context = context + "</div>";
    context = context + "</div>";
    context = context + "</div>";
    context = context + "</div>";
    context = context + "</div>";
    $("body").append(context);
    var temp_h1 = document.body.clientHeight;
    var temp_h2 = document.documentElement.clientHeight;
    $(window).resize(function () {
        $("#____lpllookmain" + ID).css("width", $(window).width() + "px").css("height", $(window).height() + "px");
        $("#____lpllookbody" + ID).css("left", ($(window).width() - dWidth) / 2 + "px").css("top", ($(window).height() - dHeight) / 2 + "px");
    });
    $("#Close" + ID).click(function () {
        $("#____lpllookmain" + ID).remove();
        $("#____lpllookbody" + ID).remove();
        window.parent.$(".scroll").css("overflow", "scroll").css("overflow-y", "scroll");
    });
}
function DialogInfoHide(ID) {
    $("#____lpllookmain" + ID).remove();
    $("#____lpllookbody" + ID).remove();
    window.parent.$(".scroll").css("overflow", "scroll").css("overflow-y", "scroll");
}


function PageReSize() {
    SetWinHeight(window.parent.$(".iframe").get(0));
}

//列表页面全选和全部不选
function CheckedEvent(ID) {
    $(".ItemChk").each(function () {
        $(this).attr("checked", $("#" + ID).attr("checked"));
    });
}

//模态窗口,使用Jquery的扩展插件Wijmo
function ShowModalDialog(url, title, width, heigth) {
    ShowDialog(url, title, width, heigth, true);
};
function ShowDialog(url, title, width, heigth, ismodal) {
    $.ImportBasePath = window.location.protocol + "//" + window.location.host + "/";
    var jsarr = new Array("Wijmo/themes/cobalt/jquery-wijmo.css", "Wijmo/themes/wijmo/jquery.wijmo.wijdialog.css", "Wijmo/external/jquery-ui-1.8.13.custom.min.js", "Wijmo/wijmo/jquery.wijmo.wijutil.js");
    $.include(jsarr, function () {
        $.include("Wijmo/wijmo/jquery.wijmo.wijdialog.js", function () {
            var myDiv = document.createElement("div");
            $(myDiv).attr("title", title);
            var dialog = $(myDiv).wijdialog({
                autoOpen: true,
                modal: ismodal,
                resizable: false,
                height: heigth,
                width: width,
                contentUrl: url,
                captionButtons: {
                    pin: { visible: true },
                    maximize: { visible: false }
                },
                show: { animated: "fade", duration: 500, easing: "easeOutExpo" },
                hide: { animated: "fade", duration: 500, easing: "easeOutExpo" },
                collapsingAnimation: "fade",
                expandingAnimation: "fade"
            });
        });

    });
};
function GetLocationHost() {
    return window.location.protocol + "//" + window.location.host + "/";
}
//confirm dialog
function ConfirmDialog(title, message, width, heigth,functionY,functionN) {
    
    $.ImportBasePath = window.location.protocol + "//" + window.location.host + "/";
    var jsarr = new Array("Wijmo/themes/cobalt/jquery-wijmo.css", "Wijmo/themes/wijmo/jquery.wijmo.wijdialog.css", "Wijmo/external/jquery-ui-1.8.13.custom.min.js", "Wijmo/wijmo/jquery.wijmo.wijutil.js");

    $.include(jsarr, function () {
        $.include("Wijmo/wijmo/jquery.wijmo.wijdialog.js", function () {
            var myP = document.createElement("p");
            myP.innerHTML = message;
            var myDiv = document.createElement("div");
            myDiv.appendChild(myP);
            $(myDiv).attr("title", title);
            var dialog = $(myDiv).wijdialog({
                autoOpen: true,
                modal: true,
                resizable: false,
                draggable: false,
                height: heigth,
                width: width,
                buttons: {
                    "是": functionY,
                    "否": functionN
                },
                captionButtons: {
                    pin: { visible: false },
                    maximize: { visible: false }
                },
                show: "drop",
                hide: "drop",
                collapsingAnimation: "fade",
                expandingAnimation: "fade"
            });
        });

    });
};